 <?php 
require_once("xml2json.php");

$group_id = $_GET['gid'];
$callback_fn = $_GET['cb'];

include("../db/opendb.php");

include("functions.php");

//$query = "select i.Path as IMAGE,l.ZIPCODE, l.TITLE, l.LONGITUDE, l.LATITUDE, l.IVR, t.Name, l.LANDING_PAGE, l.MLSNUM, l.VIRTUAL_TOUR_URL, l.STYLE, l.YEARBUILT, l.ASSOCFEE, l.STORIES, l.OID, l.LISTSTATUS, l.STREETNUM, l.STREETDIR, l.STREETNAME, l.STREETSUFFIX, l.UNITFLOORNUM, l.CITY, l.STATE, l.REMARKS, l.BEDS, l.BATHSTOTAL, l.SQFTTOTAL, l.PARKINGCOVERED, l.LISTPRICE from PROPERTIES l inner join Prop_Owner_Con p on p.Prop_OID = l.OID inner join Users u on u.ID = p.Owner left join Listing_Images i on (i.Listing_ID = l.OID and i.Main_Photo = 1) inner join Prop_Types t on t.ID = l.PROPTYPE where l.OID = '".$listing_id."' and l.LISTSTATUS in ".$in."";

$gquery = "select u.*, g.User_ID from Network_Groups_Users g inner join Users u on g.User_ID = u.ID where g.Group_ID = '".$group_id."' ";

//echo $gquery; echo "<br>";
$gresult = mysql_query($gquery) or die ("SQL Error".mysql_error());

$num_group_users = mysql_num_rows($gresult);



//$grow = mysql_fetch_assoc($gresult);
$xml = "<agents>\n";

if($num_group_users == 0)
{
$No_Agent = 0;
$xml = "<agents>\n<agent>\n";
$xml .= "\t<num_agents>".$No_Agent."</num_agents>\n";
$xml .= "</agent>\n</agents>";

}
else
{
$xml .= "\t<agent>\n";
while($grow=mysql_fetch_assoc($gresult))
{




//$query_agent = "select u.* from Users u inner join Prop_Owner_Con c on (c.Owner = u.ID and c.Prop_OID = '".$row['OID']."')";
//$result_agent = mysql_query($query_agent) or die ("SQL Error".mysql_error());
//$rowa = mysql_fetch_assoc($result_agent);


	$xml .= "\t\t<first_name>".urlencode($grow['First_Name'])."</first_name>\n";
	$xml .= "\t\t<last_name>".$grow['Last_Name']."</last_name>\n";
	$xml .= "\t\t<image>http://realivent.com/user_images/t75_".$grow['Image']."</image>\n";





}
}
$xml .= "\t</agent>\n";

$xml .= "</agents>";

$jsonContents = "";

	
	$jsonContents = "$callback_fn";
	$jsonContents .= '(';
	
    // Convert it to JSON now.
    // xml2json simply takes a String containing XML contents as input.
    $jsonContents .= xml2json::transformXmlStringToJson($xml);

	$jsonContents .= ')';


    //echo("JSON formatted output generated by xml2json:\n\n");
    echo($jsonContents);

?>
